package com.sali.commons.disruptor;

import com.lmax.disruptor.WorkHandler;
import com.sali.entity.TransferObject;
import com.sali.service.data_processor.chain.ProcessChainContext;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

// 数据处理的执行者
public class DataProcessHandler implements WorkHandler<DataProcessEvent> {

    private static final Logger logger = LoggerFactory.getLogger(WorkHandler.class);

    private ProcessChainContext processChainContext;

    public DataProcessHandler(ProcessChainContext processChainContext) {
        this.processChainContext = processChainContext;
    }

    @Override
    public void onEvent(DataProcessEvent dataProcessEvent) throws Exception {
        try {
            TransferObject obj = dataProcessEvent.getVal();
            processChainContext.process(obj);
        } catch (Exception e) {
            logger.error("disruptor消费报错：{}", e.getMessage(), e);
        }
    }
}
